package kr.pe.johnkim.chattingday.mobile.rest.dao;

import kr.pe.johnkim.chattingday.mobile.domain.ChattingDayMember;
import kr.pe.johnkim.chattingday.mobile.domain.ChattingDayMemberBlocked;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;

import java.util.List;

/**
 * Chatting Day 사용자 차단 관련 DAO 메소드들을 구현하는 클래스 이다.
 * 
 * @author : johnkim <cale9797@gmail.com / Bettersoft Inc,.>
 * @Date : 12. 5. 29
 */
public class ChattingDayMemberBlockedDaoImpl extends SqlMapClientDaoSupport implements ChattingDayMemberBlockedDao {

    // SLF4J Logging
    private Logger logger = LoggerFactory.getLogger(ChattingDayMemberBlockedDaoImpl.class);

    /**
     * 차단 사용자를 등록 한다.
     *
     * @param chattingDayMemberBlocked
     * @return
     */
    @Override
    public boolean registerMemberBlocked(ChattingDayMemberBlocked chattingDayMemberBlocked) {
        logger.info("registerMemberBlocked");

        boolean result;
        
        try {
            getSqlMapClientTemplate().insert("CHATTINGDAY_MEMBER_BLOCKED.registerMemberBlocked", chattingDayMemberBlocked);
            result = true;
        } catch (Exception e) {
            result = false;
        }

        return result;
    }

    /**
     * 차단 사용자를 비활성화 한다.
     *
     * @param chattingDayMemberBlocked
     * @return
     */
    @Override
    public boolean updateDeactivateMemberBlocked(ChattingDayMemberBlocked chattingDayMemberBlocked) {
        logger.info("updateDeactivateMemberBlocked");

        boolean result;

        try {
            getSqlMapClientTemplate().update("CHATTINGDAY_MEMBER_BLOCKED.updateDeactivateMemberBlocked", chattingDayMemberBlocked);
            result = true;
        } catch (Exception e) {
            result = false;
        }

        return result;
    }

    /**
     * 차단 사용자 목록을 가져 온다.
     *
     * @param chattingDayMemberBlocked
     * @return
     */
    @Override
    public List<ChattingDayMemberBlocked> selectMemberBlockedList(ChattingDayMemberBlocked chattingDayMemberBlocked) {
        logger.info("selectMemberBlockedList");
        
        return this.getSqlMapClientTemplate().queryForList("CHATTINGDAY_MEMBERS.selectMemberBlockedList", chattingDayMemberBlocked);
    }

    /**
     * 차단 사용자 정보를 가져 온다.
     *
     * @param chattingDayMemberBlocked
     * @return
     */
    @Override
    public ChattingDayMember selectMemberBlockedInformation(ChattingDayMemberBlocked chattingDayMemberBlocked) {
        logger.info("selectMemberBlockedInformation");

        return (ChattingDayMember)getSqlMapClientTemplate().queryForObject("CHATTINGDAY_MEMBERS.selectMemberBlockedInformation", chattingDayMemberBlocked);
    }

    /**
     * 차단 사용자 총 명수를 가져 온다.
     *
     * @param chattingDayMemberBlocked
     * @return
     */
    @Override
    public ChattingDayMemberBlocked selectMemberBlockedCount(ChattingDayMemberBlocked chattingDayMemberBlocked) {
        logger.info("selectMemberBlockedCount");

        return (ChattingDayMemberBlocked)getSqlMapClientTemplate().queryForObject("CHATTINGDAY_MEMBERS.selectMemberBlockedCount", chattingDayMemberBlocked);
    }
}
